﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Json;
using System.IO;
using Newtonsoft.Json;
using System.Collections;

namespace Empires.CRL.Tools
{
    public static class SerializerLib
    {
        public static string JsonSerializer<T>(T t)
        {
            if (t == null)
            {
                return null;
            }
            return JsonConvert.SerializeObject(t);
        }
         public static T JsonDeserialize<T>(string json)  
         {
             try
             {
                 return JsonConvert.DeserializeObject<T>(json);
             }
             catch (Exception ex)
             {
                 return default(T);
             }

         }
    }

    public static class Utils
    {
        static Hashtable table;
        static Utils()
        {
            table = new Hashtable();
        }
        public static string ReadAppSetting(string key)
        {
            if (table[key] == null)
            {
                System.Configuration.AppSettingsReader reader = new System.Configuration.AppSettingsReader();
                object value = reader.GetValue(key, typeof(String));
                if (value != null)
                {

                    table.Add(key, value.ToString());
                }
            }
            return table[key].ToString();
        }

    }
}
